<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/22
 * Time: 15:30
 */
include "../conn.php";

if(isset($_POST["newId"])) {
    $id = $_POST["newId"];
    $title = $_POST["title"];
    $content = $_POST["content"];
    $type = $_POST["type"];
    $author = $_POST["author"];
}

$indexId=isset($_POST["indexId"])?$_POST["indexId"]:null;  //删除数据
$time=date("Y-m-d");
$bt=isset($_POST["actionType"])?$_POST["actionType"]:null;




if($bt=="保存")//修改数据
{
    $sql="update defensesummary set newname='$title',category='$type',author='$author',
    content='$content' WHERE newsid=$id";
    if(mysqli_query($conn,$sql)){
        header("Location:a-newsManage.php");
    }
    else {
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }
}
if($bt=="添加")//添加数据
{
    $sql = "select max(newsid) from defensesummary";
    $result = mysqli_query($conn, $sql);
    $row = mysqli_fetch_row($result);
    $titleId = $row[0] + 1;

    $sql="Insert into defensesummary
VALUES ($titleId,'$title','2018','$type','$author','$content','$time')";
    if (mysqli_query($conn, $sql)) {

        header("Location:a-newsManage.php");
    } else {
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }
}
if($bt=="delete")
{
    $sql="delete from defensesummary WHERE newsid=$indexId ";
    if (mysqli_query($conn, $sql))
    {
        echo "success";
    }
    else{
        echo "failed";
    }
}

if($bt=="open")
{
    $year=$_POST['year'];
    $sql="update statetable set yearstate=1 WHERE year=$year";
    if(mysqli_query($conn,$sql)){
        echo "开放".$year."年毕业设计管理成功";
    }
    else
        echo "error";

}

if($bt=="down")
{
    $year=$_POST['year'];
    $sql="update statetable set yearstate=0 WHERE year=$year";
    if(mysqli_query($conn,$sql)){
        echo "关闭".$year."年毕业设计管理成功";
    }
    else
        echo "error";
}



?>
